package org.example.school.controller;

import org.example.school.business.TeacherInfo;
import org.example.school.common.Result;
import org.example.school.entity.Leave;
import org.example.school.model.dto.AttendanceRecordsVo;
import org.example.school.model.dto.TeachingClassDTO;
import org.example.school.model.dto.leaveBySelectDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/teacher")
@CrossOrigin
public class TeacherController {
    @Autowired
    private TeacherInfo teacherInfo;
    
    /**
     * 查询当天未打卡学生
     * @param date 日期，不传则为当天
     * @return 未打卡学生列表
     */
    @GetMapping("/absent-students")
    public Result<List<AttendanceRecordsVo>> getAbsentStudents(@RequestParam(required = false) LocalDate date) {
        try {
            List<AttendanceRecordsVo> absentStudents = teacherInfo.getAbsentStudents(date);
            return Result.success(absentStudents);
        } catch (Exception e) {
            return Result.error("查询失败: " + e.getMessage());
        }
    }
    
    //查询学生请假信息
    @PostMapping("/leave-students")
    public Result<List<Leave>> getLeaveStudents(@RequestBody leaveBySelectDTO leaveBySelectDTO) {
        try {
            List<Leave> list = teacherInfo.getLeaveStudents(leaveBySelectDTO);
            return Result.success(list);
        } catch (Exception e) {
            return Result.error("查询失败: " + e.getMessage());
        }
    }
    
    //修改学生请假信息
    @PostMapping("/update-leave")
    public Result<String> updateLeave(@RequestParam String leaveId, @RequestParam String status) {
        try {
            String result = teacherInfo.updateLeave(leaveId, status);
            return Result.success(result);
        } catch (Exception e) {
            return Result.error("修改失败: " + e.getMessage());
        }
    }
    
    //获取授课班级
    @GetMapping("/classes")
    public Result<List<TeachingClassDTO>> getTeachingClasses() {
        try {
            List<TeachingClassDTO> classes = teacherInfo.getTeachingClasses();
            return Result.success(classes);
        } catch (Exception e) {
            return Result.error("获取授课班级失败: " + e.getMessage());
        }
    }
    //根据
}